package com.hsc.yalebao.base;

import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;

import com.hsc.yalebao.http.AppConstants;
import com.hsc.yalebao.weight.MyDialog1;

import java.util.Stack;

public class ActivityStack {

    private static Stack<Activity> activityStack;
    private static ActivityStack instance = new ActivityStack();
    private MyDialog1 myDialog1;

    public static Stack<Activity> getActivityStack() {
        return activityStack;
    }

    public static ActivityStack getInstance() {
        return instance;
    }

    public static void setActivityStack(Stack<Activity> paramStack) {
        activityStack = paramStack;
    }

    public void backTo(Class<?> paramClass) {
        String str = null;
        if (paramClass != null) {
            Log.i("popActivity", paramClass.getName());
            str = paramClass.getName();
        }
        while (true) {
            if ((activityStack.isEmpty()) || (((Activity) activityStack.peek()).getLocalClassName().equalsIgnoreCase(str)))
                return;
            ((Activity) activityStack.pop()).finish();
        }
    }

    public void backToMain(final Class<?> paramClass, Context paramContext) {
        if (!CustomApplication.app.isLogin)
            return;
        AppConstants.NO_LOGIN_TOKEN = "";
        CustomApplication.app.isLogin = false;
        CustomApplication.app.userBaseBean = null;
        CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_PWD, "");
        com.hsc.yalebao.http.RequestNet.accessToken = "";
        CustomApplication.app.preferencesUtil.setValue(AppConstants.LOGIN_TYPE, "0");
        if (this.myDialog1 == null) {
            this.myDialog1 = new MyDialog1(paramContext);
            this.myDialog1.setMessage("长时间未登录，需要重新登录！");
            this.myDialog1.setOnKeyListener(new DialogInterface.OnKeyListener() {
                public boolean onKey(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt, KeyEvent paramAnonymousKeyEvent) {
                    if ((paramAnonymousInt == 4) && (paramAnonymousKeyEvent.getRepeatCount() == 0)) {
                        ActivityStack.this.myDialog1.dismiss();
                        ActivityStack.this.myDialog1 = null;
                        return false;
                    }
                    return true;
                }
            });
            this.myDialog1.btn_confirm.setOnClickListener(new View.OnClickListener() {
                public void onClick(View paramAnonymousView) {
                    String str = null;
                    if (paramClass != null) {
                        Log.i("popActivity", paramClass.getName());
                        str = paramClass.getName();
                    }
                    while (true) {
                        if ((ActivityStack.activityStack.isEmpty()) ||
                                (((Activity) ActivityStack.activityStack.peek()).getLocalClassName().equalsIgnoreCase(str))) {
                            MainActivity.mainActivity.performClickBtn(0);
                            MainActivity.mainActivity.showLoginPop();
                            ActivityStack.this.myDialog1.dismiss();
                            ActivityStack.this.myDialog1 = null;
                            return;
                        }
                        ((Activity) ActivityStack.activityStack.pop()).finish();
                    }
                }
            });
        }
        this.myDialog1.show();
    }


    public void close() {
        Activity localActivity = currentActivity();
        activityStack.remove(localActivity);
        while (!activityStack.isEmpty())
            ((Activity) activityStack.pop()).finish();
        localActivity.finish();
    }

    public Activity currentActivity() {
        boolean bool = activityStack.empty();
        Activity localActivity = null;
        if (!bool)
            localActivity = (Activity) activityStack.lastElement();
        return localActivity;
    }


    public void popActivity(Activity paramActivity) {
        if (paramActivity != null) {
            Log.i("popActivity", paramActivity.getPackageName() + "." + paramActivity.getLocalClassName());
            paramActivity.finish();
            activityStack.remove(paramActivity);
        }
    }

    public void pushActivity(Activity paramActivity) {
        if (activityStack == null)
            activityStack = new Stack();
        activityStack.add(paramActivity);
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.base.ActivityStack
 * JD-Core Version:    0.6.2
 */